home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 113_01 / a68put.c < prev    next >
Text File  |  1985-03-09  |  5KB  |  181 lines

  1. /*
  2.     HEADER:        CUG113;
  3.     TITLE:        6800 Cross-Assembler (BDS C Version);
  4.     FILENAME:    A68PUT.C;
  5.     VERSION:    2.6;
  6.     DATE:        07/22/1985;
  7.  
  8.     DESCRIPTION:    "This program lets you use your CP/M-80-based computer
  9.             to assemble code for the Motorola 6800, 6801, 6802,
  10.             6803, 6808, and 68701 microprocessors.  The program is
  11.             written in BDS C for the best possible performance on
  12.             8-bit machines.  All assembler features are supported
  13.             except relocation, linkage, listing control, and
  14.             macros.";
  15.  
  16.     KEYWORDS:    Software Development, Assemblers, Cross-Assemblers,
  17.             Motorola, MC6800, MC6801;
  18.  
  19.     SEE-ALSO:    CUG149, 6801 Cross-Assembler (Portable);
  20.  
  21.     SYSTEM:        CP/M-80;
  22.     COMPILERS:    BDS C;
  23.  
  24.     WARNINGS:    "This package is specifically tailored to CP/M-80
  25.             machines and the rather non-standard, but high-
  26.             performance BDS C compiler.  For other environments,
  27.             use the portable version of this package on CUG149.";
  28.  
  29.     AUTHORS:    William C. Colley III;
  30. */
  31.  
  32. /*
  33.     6800/6801 Cross-Assembler  v. 2.6
  34.  
  35.     May, 1980
  36.  
  37.     July, 1980 -- Rev. 2.2 consisting of fixing the M errors that
  38.         come from forward references in FDB and FCB pseudo-ops.
  39.  
  40.     October, 1980 -- Rev. 2.3 consisting of updating the assembly
  41.         language file and I/O routines to match and take
  42.         advantage of BDS C V1.4.
  43.  
  44.     October, 1983 -- Rev. 2.4 consisting of adding the CPU pseudo-op,
  45.         adding the 6801 CPU's extra opcodes, and speeding up the
  46.         code a bit.
  47.  
  48.     September, 1984 -- Rev. 2.5 consisting of fixing bugs with the symbol
  49.         table sort, the writing of files to specified drives, and the
  50.         handling of blank input lines.
  51.  
  52.     June, 1985 -- Rev. 2.6 consisting of fixing a bug in the IF block
  53.         nesting mechanism.
  54.  
  55.     Copyright (c) 1980,83,84,85 William C. Colley, III.
  56.  
  57. File:    a68put.c
  58.  
  59. List and hex output routines.
  60. */
  61.  
  62. /*  Get globals:  */
  63.  
  64. #include "a68.h"
  65.  
  66. /*
  67. Function to form the list output line and put it to
  68. the list device.  Routine also puts the line to the
  69. console in the event of an error.
  70. */
  71.  
  72. lineout()
  73. {
  74.     char tbuf[25], *tptr, *bptr, count;
  75.  
  76.     if (list == NOFILE && errcode == ' ') return;
  77.     setmem(tbuf,24,' ');  tbuf[24] = '\0';  tptr = tbuf;
  78.     *tptr++ = errcode;  ++tptr;
  79.     if (hexflg != NOCODE) { puthex4(address,&tptr);  tptr += 3; }
  80.     else tptr += 7;
  81.     count = 0;  bptr = binbuf;
  82.     for (;;) {
  83.     if (count == nbytes || (count && count % 4 == 0)) {
  84.         if (list != NOFILE) {
  85.         fputs(tbuf,list);
  86.         if (count > 4) fputs("\n",list);
  87.         else fputs(linbuf,list);
  88.         }
  89.         if (list != CONO && errcode != ' ') {
  90.         puts(tbuf);
  91.         if (count >= 4) putchar('\n');
  92.         else puts(linbuf);
  93.         }
  94.         tptr = tbuf + 2;  puthex4(address,&tptr);
  95.         setmem(tptr,14,' ');  tptr += 3;
  96.     }
  97.     if (count++ == nbytes) return;
  98.     ++address;  puthex2(*bptr++,&tptr);  tptr++;
  99.     }
  100. }
  101.  
  102. /*
  103. Function to form the hex output line and put it to
  104. the hex output device.
  105. */
  106.  
  107. hexout()
  108. {
  109.     char count, *bptr;
  110.  
  111.     if (hex == NOFILE) return;
  112.     switch (hexflg) {
  113.     case PUTCODE:    bptr =binbuf;
  114.             for (count = 1; count <= nbytes; count++) {
  115.                 puthex2(*bptr,&hxlnptr);  chksum += *bptr++;
  116.                 if (++hxbytes == 16) flshhbf(pc+count);
  117.             }
  118.  
  119.     case NOCODE:    return;
  120.  
  121.     case FLUSH:    flshhbf(pc);  return;
  122.  
  123.     case NOMORE:    flshhbf(0);  fputs(":0000000000\n\032",hex);
  124.             fflush(hex);  fclose(hex);  return;
  125.     }
  126. }
  127.  
  128. /*
  129. Function to put a line of intel hex to the appropriate
  130. device and get a new line started.
  131. */
  132.  
  133. flshhbf(loadaddr)
  134. unsigned loadaddr;
  135. {
  136.     if (hxbytes != 0) {
  137.     puthex2(-(chksum+hxbytes),&hxlnptr);  *hxlnptr++ = '\n';
  138.     *hxlnptr++ = '\0';  hxlnptr = hxlnbuf + 1;
  139.     puthex2(hxbytes,&hxlnptr);  fputs(hxlnbuf,hex);
  140.     }
  141.     hxbytes = 0;  hxlnptr = hxlnbuf;  *hxlnptr++ = ':';
  142.     hxlnptr += 2;  puthex4(loadaddr,&hxlnptr);  puthex2(0,&hxlnptr);
  143.     chksum = (loadaddr >> 8) + (loadaddr & 0xff);
  144. }
  145.  
  146. /*
  147. Function to put a 4-digit hex number into an output line.
  148. */
  149.  
  150. puthex4(number,lineptr)
  151. unsigned number;
  152. char **lineptr;
  153. {
  154.     puthex2(number>>8,lineptr);  puthex2(number,lineptr);
  155. }
  156.  
  157. /*
  158. Function to put a 2-digit hex number into an output line.
  159. */
  160.  
  161. puthex2(number,lineptr)
  162. char number, **lineptr;
  163. {
  164.     if ((**lineptr = (number >> 4) + '0') > '9') **lineptr += 7;
  165.     if ((*++*lineptr = (number & 0xf) + '0') > '9') **lineptr += 7;
  166.     ++(*lineptr);
  167. }
  168.  
  169. /*
  170. Function to put a decimal number into an output line.
  171. */
  172.  
  173. putdec(number,lineptr)
  174. unsigned number;
  175. char **lineptr;
  176. {
  177.     if (!number) return;
  178.     putdec(number/10,lineptr);
  179.     *(*lineptr)++ = number % 10 + '0';
  180. }
  181. ,&hxlnptr);  *hxlnptr+